<?php

namespace IDock\Insurance\HBIC\Response;

use IDock\Http\Request;
use IDock\Http\Response;

class AResponse extends Response
{

    protected $status = '';

    protected $logicStatus = '';

    public function resolve(): Response
    {
        $body = $this->getBody();

        if ($body) {
            $xml = simplexml_load_string($body);
            $body = json_decode(json_encode($xml),true);
            $errorCode = $body['HEAD']['ERROR_CODE'] ?? '';
            $message = $body['HEAD']['ERROR_MESSAGE'] ?? '';
            $this->setBody($body);
            if ($errorCode != '0000') {
                $this->setError(  ($errorCode ?: '') .":".$message);
                return  $this;
            }
        }

        return $this;
    }

    /**
     * @return string
     */
    public function getStatus(): string
    {
        return $this->status;
    }

    /**
     * @return string
     */
    public function getLogicStatus(): string
    {
        return $this->logicStatus;
    }


}